<?php
class ActiveRecord extends CActiveRecord
{
	const DATE_EMPTY = '0000-00-00 00:00:00';

	/**
	 * @see parent::getDbConnection
	 * @return DbConnection
	 */
	public function getDbConnection()
	{
		if (isset(static::$dbComponentName)) {
			$db = Yii::app()->getComponent(static::$dbComponentName);
			$db->setActive(true);
		} else {
			$db = parent::getDbConnection();
		}
		return $db;
	}

	/**
	 * @param string $str
	 * @return array
	 */
	public static function extractSqlCommands($str)
	{
		$res = array();
		$sqlCommands = (array) explode(';', $str);
	    foreach ($sqlCommands as $sqlCommand) {
		    $sqlCommand = trim($sqlCommand);
		    if ($sqlCommand) {
				$res[] = $sqlCommand;
			}
	    }
		return $res;
	}

	public function deleteAllByIds(array $ids)
	{
		return static::model()->deleteAllByAttributes(array(
			'id' => $ids
		));
	}
}
